home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / fl_arc.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.2 KB  |  78 lines

  1. //
  2. // "$Id: fl_arc.cxx,v 1.4 1999/01/07 19:17:35 mike Exp $"
  3. //
  4. // Arc functions for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Utility for drawing arcs and circles.  They are added to
  27. // the current fl_begin/fl_vertex/fl_end path.
  28. // Incremental math implementation:
  29.  
  30. #include <FL/fl_draw.H>
  31. #include <FL/math.h>
  32.  
  33. void fl_arc(double x, double y, double r, double start, double end) {
  34.  
  35.   // draw start point accurately:
  36.   double A = start*(M_PI/180);
  37.   double X = r*cos(A);
  38.   double Y = -r*sin(A);
  39.   fl_vertex(x+X,y+Y);
  40.  
  41.   // number of segments per radian:
  42.   int n; {
  43.     double x1 = fl_transform_dx(r,0);
  44.     double y1 = fl_transform_dy(r,0);
  45.     double r1 = x1*x1+y1*y1;
  46.     x1 = fl_transform_dx(0,r);
  47.     y1 = fl_transform_dy(0,r);
  48.     double r2 = x1*x1+y1*y1;
  49.     if (r2 < r1) r1 = r2;
  50.     n = int(sqrt(r1)*.841471);
  51.     if (n < 2) n = 2;
  52.   }
  53.   double epsilon = 1.0/n;
  54.   double E = end*(M_PI/180);
  55.   int i = int((E-A)*n);
  56.   if (i < 0) {i = -i; epsilon = -epsilon;}
  57.   double epsilon2 = epsilon/2;
  58.   for (; i>1; i--) {
  59.     X += epsilon*Y;
  60.     Y -= epsilon2*X;
  61.     fl_vertex(x+X,y+Y);
  62.     Y -= epsilon2*X;
  63.   }
  64.  
  65.   // draw the end point accurately:
  66.   fl_vertex(x+r*cos(E), y-r*sin(E));
  67. }
  68.  
  69. #if 0 // portable version.  X-specific one in fl_vertex.C
  70. void fl_circle(double x,double y,double r) {
  71.   _fl_arc(x, y, r, r, 0, 360);
  72. }
  73. #endif
  74.  
  75. //
  76. // End of "$Id: fl_arc.cxx,v 1.4 1999/01/07 19:17:35 mike Exp $".
  77. //
  78.